/*
 * @Descripttion:
 * @version:
 * @Author: hhy
 * @Date: 2020-12-04 16:58:53
 * @LastEditors: hhy
 * @LastEditTime: 2021-01-29 17:57:06
 */
import {
  getToken,
  removeToken,
  removeItem,
  setItem
} from "@/utils/storage";
// import api from "@/config/api";
import {
  ManageExit
} from "@/api/login";
import router from "@/router/index.js";
export default {
  namespaced: true,
  state: {
    //用户token
    token: getToken(),
    //用户信息
    userInfo: {},
  },
  mutations: {
    SET_TOKEN: (state, token) => {
      state.token = token;
    },
    USER_INFO: (state, roles) => {
      setItem("userInfo", roles);
      state.userInfo = roles;
    },
  },
  actions: {
    // 前端 登出
    async FedLogOut(state) {
      await ManageExit();
      state.token = "";
      removeToken();
      sessionStorage.clear();
      removeItem("userInfo");
      router.replace("/login");
    },
    //获取用户信息
    userInfo({ commit }, data) {
      commit("USER_INFO", data);
    },
  },
};
